﻿using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text;
using cz.uhul.DSMLv2;

namespace testDSML
{
  class testDnRegex
  {



    public static void go()
    {

      LdDistinguishedName dn = LdDistinguishedName.Parse("CN=Bob,OU=HR1,DC=Example,DC=COM");

      Regex.CacheSize = 100;
      RegexOptions rgOpt = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.Multiline;


      //DN expression regex pattern
      string pattern1 = @"^\s?(?<rdn>\w[^=]*[=]{1}[^,]*),(?<path>\s?(?<rdn>\w[^=]*[=]{1}[^,]*)(,\s?(?<rdn>\w[^=]*[=]{1}[^,]*))*)";
      string pattern2 = @"^\s?(?<rdn>\w[^=]*[=]{1}[^,]*)";

      Regex _tokenRegex1 = new Regex(pattern1, rgOpt);
      Regex _tokenRegex2 = new Regex(pattern2, rgOpt);

      string vyraz = "cn=Středočeský kraj,cn=NUTS 3,cn=CZ NUTS,cn=správní členění,o=čsú, c=cz";
      //vyraz = "CN=Bob,OU=HR1,DC=Example,DC=COM";
      //vyraz = "CN=Bob";

      Match m1 = _tokenRegex1.Match(vyraz);
      Match m2 = _tokenRegex2.Match(vyraz);

      string rdn;
      string path;

      Console.WriteLine(m1.Success);
      Console.WriteLine(m2.Success);


      LdDistinguishedName testName = vyraz;

    }


  }
}
